package s2elinshu;

import java.util.Scanner;

import s2elinshu.model.SungJuk2VO;

import java.util.Scanner;

public class J16Ch05Calculator{
	public static void main(String[] args) {
		String msg = "두 정수와 연산자를 입력해주세요.";
		Scanner sc = new Scanner(System.in);
		
		System.out.println( msg );
		int x = sc.nextInt();
		int y = sc.nextInt();
		String type = sc.next();
		
		// 업캐스팅을 활용해서 4개의 객체(add, sub, mul, div)를 생성 했던걸 수퍼 클래스 J16Cal을 이용해서 한번에 해결
		J16Cal cal =null;
		J16CalService cs = new J16CalService();

		switch (type) {
		case "+" : 
			cal = new J16Add(); 
			cal.setValue( x, y );
			cs.calculate(cal, "+");
			break;
		case "-" : 
			cal = new J16Sub();
			cal.setValue(x, y);
			cs.calculate(cal, "-");
			break;
		case "*" : 
			cal = new J16Mul();
			cal.setValue(x, y);
			cs.calculate(cal, "*");
			break;
		case "/" : 
			cal = new J16Div();
			cal.setValue(x, y);
			cs.calculate(cal, "/");
			break;
		}
	}
}

class J16Cal {
	private int x;
	private int y;
	
	public void setValue( int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	public int getX() { return x; }
	public void setX(int x) { this.x = x; }

	public int getY() { return y; }
	public void setY(int y) { this.y = y; }
	
	@Override
	public String toString() {
		String result = "";
		result += x + "/" + y;
		return result;
	}
}

class J16Add extends J16Cal { }
class J16Sub extends J16Cal { }
class J16Mul extends J16Cal { }
class J16Div extends J16Cal { }

interface J16CalIService {
	void calculate(J16Cal cal, String type) ;
}

class J16CalService implements J16CalIService {

	@Override
	public void calculate(J16Cal cal, String type) {
		int result = 0;
		switch(type) {
			case "+" : result = cal.getX() + cal.getY();
			break;
			case "-" : result = cal.getX() - cal.getY();
			break;
			case "*" : result = cal.getX() * cal.getY();
			break;
			case "/" : result = cal.getX() / cal.getY();
			break;
		}
		System.out.println(result);
	}
}